package com.bite.principle.controller;

import com.bite.principle.model.Dog;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/scope")
@RestController
public class ScopeController {
    @Resource(name = "singleDog")
    private Dog singleDog;

    @Resource(name = "prototypeDog")
    private Dog prototypeDog;


    @Resource(name = "requestDog")
    private Dog requestDog;

    @Resource(name = "sessionDog")
    private Dog sessionDog;

    @Resource(name = "applicationDog")
    private Dog applicationDog;

    @Autowired
    private ApplicationContext context;

    @RequestMapping("/single")
    public String single(){
        //从context中获取对象
        Dog dog = (Dog)context.getBean("singleDog");
        return "注入对象:"+ singleDog.toString() + ",context Dog:"+ dog.toString();
    }

    @RequestMapping("/prototype")
    public String prototype(){
        //从context中获取对象
        Dog dog = (Dog)context.getBean("prototypeDog");
        return "注入对象:"+ prototypeDog.toString() + ",context Dog:"+ dog.toString();
    }


    @RequestMapping("/request")
    public String request(){
        //从context中获取对象
        Dog dog = (Dog)context.getBean("requestDog");
        return "注入对象:"+ requestDog.toString() + ",context Dog:"+ dog.toString();
    }


    @RequestMapping("/session")
    public String session(){
        //从context中获取对象
        Dog dog = (Dog)context.getBean("sessionDog");
        return "注入对象:"+ sessionDog.toString() + ",context Dog:"+ dog.toString();
    }

    @RequestMapping("/application")
    public String application(){
        //从context中获取对象
        Dog dog = (Dog)context.getBean("applicationDog");
        return "注入对象:"+ applicationDog.toString() + ",context Dog:"+ dog.toString();
    }




}
